$.ajaxSetup({
	cache: true,
	complete: function(XMLHttpRequest, textStatus) {
		var status = XMLHttpRequest.status;
		if (status == 401) {
			alert('您还未登录，或您的登录超时，或您的账号在其他地方已登录！');
			// location.reload(true);
		}
		if (status == 403) {
			alert('系统异常，请联系在线客服！');
		}
	}
});

// 当前游戏代码
var currShortName = 'xy28';
/**
 * 按游戏类型初始化
 * 
 * @param shortName 游戏代码
 * 		xy28 - 北京
 *      twxy28 - 台湾
 *      jndxy28 - 加拿大
 *      azxy28 - 澳大利亚
 *      hgxy28 - 韩国
 *      slfkxy28 - 斯洛伐克
 *      jndxxy28 - 加拿大西
 */
function init(shortName) {
	clearTimeout(loadOpenTimeIndex);
	clearTimeout(opencodeTimeOut);
	
	history.replaceState('', '', (currentRootDirectory + window.location.pathname + "?code=" + shortName));
	var gameName = "";
	switch (shortName) {
		case 'xy28':
			gameName = '北京';
			break;
		case 'twxy28':
			gameName = '台湾';
			break;
		case 'jndxy28':
			gameName = '加拿大';
			break;
		case 'azxy28':
			gameName = '澳洲';
			break;
		case 'hgxy28':
			gameName = '韩国';
			break;
		case 'slfkxy28':
			gameName = '斯洛伐克';
			break;
		case 'jndxxy28':
			gameName = '加拿大西';
			break;
		case 'jndbsxy28':
			gameName = '加拿大卑斯';
			break;
		case 'xdlxy28':
			gameName = '新德里';
			break;
		case 'sgxy28':
			gameName = '新加坡';
			break;
		case 'djxy28':
			gameName = '东京';
			break;
		case 'jzdxy28':
			gameName = '济州岛';
			break;
		case 'ldxy28':
			gameName = '伦敦';
			break;
		case 'xdjxy28':
			gameName = '新东京';
			break;
		case 'xhgxy28':
			gameName = '新韩国';
			break;

		case 'xjp30mxy28':
			gameName = '新加坡30秒';
			break;
		case 'md30mxy28':
			gameName = '缅甸30秒';
			break;
		case 'mdsfxy28':
			gameName = '缅甸三分';
			break;
		case 'mdffxy28':
			gameName = '缅甸一分';
			break;
		case 'jpzwfxy28':
			gameName = '柬埔寨五分';
			break;
		case 'jpzffxy28':
			gameName = '柬埔寨一分';
			break;
		case 'jpz30mxy28':
			gameName = '柬埔寨30秒';
			break;
		case 'flblfxy28':
			gameName = '菲律宾两分';
			break;
		case 'flbffxy28':
			gameName = '菲律宾一分';
			break;
		case 'flb30mxy28':
			gameName = '菲律宾30秒';
			break;
		case 'jndssmxy28':
			gameName = '加拿大30秒';
			break;
		case 'jndyfxy28':
			gameName = '加拿大一分';
			break;
		case 'nftycswmxy28':
			gameName = '南非太阳城45秒';
			break;
		case 'lswjsswmxy28':
			gameName = '拉斯维加斯45秒';
			break;
		case 'jlpswmxy28':
			gameName = '吉隆坡45秒';
			break;
		case 'hnswmxy28':
			gameName = '河内45秒';
			break;
		case 'dldswmxy28':
			gameName = '多伦多45秒';
			break;
		case 'bdswmxy28':
			gameName = '巴登45秒';
			break;
		case 'xdjswmxy28':
			gameName = '新东京45秒';
			break;
		case 'xhgswmxy28':
			gameName = '新韩国45秒';
			break;
		case 'ldswmxy28':
			gameName = '伦敦45秒';
			break;
		case 'jzdswmxy28':
			gameName = '济州岛45秒';
			break;
		case 'xdlswmxy28':
			gameName = '新德里45秒';
			break;
		case 'xjpswmxy28':
			gameName = '新加坡45秒';
			break;
		case 'flbswmxy28':
			gameName = '菲律宾45秒';
			break;
		case 'jpzswmxy28':
			gameName = '柬埔寨45秒';
			break;
		case 'mdswmxy28':
			gameName = '缅甸45秒';
			break;
		case 'blsswmxy28':
			gameName = '比利时45秒';
			break;
		default:
			return;
	}
	currShortName = shortName;
	way.set("xy28.gameName", gameName);
	
	getCurrlimitred(shortName);
	getOpenCodeList(shortName);

	loadOpenTime(shortName);
	getOpenCodeDayList(shortName);
	getUserBetsListToday(shortName);
}

/**
 * 获取当前限红
 * @param shortName 代码
 */
function getCurrlimitred(shortName) {
	$.ajax({
		type: "post",
		url: "/ct-data/getCurrlimitred",
		data: {
			"shortName": shortName
		},
		datatype: "json",
		async: false,
		success: function(msg) {
			if (msg.sign === true) {
				if(msg.limitred){
                    way.set("http://www.yugj881.com/resources/main/currlimitred.id", msg.limitred.id);
                    way.set("http://www.yugj881.com/resources/main/currlimitred.name", msg.limitred.name);
                    way.set("currlimitred.mixmoney", msg.limitred.mixmoney);
                    way.set("currlimitred.maxmoney", msg.limitred.maxmoney);
				}
			}
		}
	});
}

/**
 * 获取游戏子集
 * @param type 游戏种类
 * @param xycCode 当前游戏
 */
function getGameList(type, xycCode) {
	$.ajax({
		type: "post",
		url: "/ct-data/loadLottery",
		data: {
			"type": type
		},
		datatype: "json",
		success: function(msg) {
			if (msg.sign === true) {
				var list = [];
				$.each(msg.list, function(idx, val) {
					if (val.shortName == xycCode) {
						list.unshift(val);
					} else {
						list.push(val);
					}
				});
				var currentGameHtml = '';
				var gameListHtml = '';
				var isNotHaveCurrentGame = true;
				$.each(list, function(idx, val) {
					var showName = val.showName;
					if (showName == '幸运28') {
						showName = '北京';
					} else {
						showName = showName.replace('幸运28', '');
					}
					if (isNotHaveCurrentGame) {
						if (val.state !== 0) {
							isNotHaveCurrentGame = false;
							currShortName = val.shortName;
							/*currentGameHtml += '<em><img src="../../resources/yiyou/images/guoqi/';
							switch (val.shortName) {
								case 'jndxy28':
									currentGameHtml += 'guoqi2';
									break;
								case 'azxy28':
									currentGameHtml += 'guoqi3';
									break;
								case 'hgxy28':
									currentGameHtml += 'guoqi4';
									break;
								case 'slfkxy28':
									currentGameHtml += 'guoqi5';
									break;
								case 'jndxxy28':
									currentGameHtml += 'guoqi6';
									break;
								case 'jndbsxy28':
									currentGameHtml += 'guoqi7';
									break;
								default:
									currentGameHtml += 'guoqi1';
									break;
							}
							currentGameHtml += '.png" width="34" height="18"></em>';
							 */
							// currentGameHtml += '<span>' + showName + '</span>';
							// <p>北京 <span>﹀</span></p>
							currentGameHtml += '<span>' + showName + '<em>﹀</em></span>';
							currentGameHtml += '<input type="hidden" value="' + val.shortName + '">';
							// currentGameHtml += '<i></i>';
						}
					} else if (val.state !== 0) {
						gameListHtml += '<p state="' + val.state + '">';
						// gameListHtml += '<em><img src="../../resources/yiyou/images/guoqi/';
						// switch (val.shortName) {
						// 	case 'jndxy28':
						// 		gameListHtml += 'guoqi2';
						// 		break;
						// 	case 'azxy28':
						// 		gameListHtml += 'guoqi3';
						// 		break;
						// 	case 'hgxy28':
						// 		gameListHtml += 'guoqi4';
						// 		break;
						// 	case 'slfkxy28':
						// 		gameListHtml += 'guoqi5';
						// 		break;
						// 	case 'jndxxy28':
						// 		gameListHtml += 'guoqi6';
						// 		break;
						// 	case 'jndbsxy28':
						// 		gameListHtml += 'guoqi7';
						// 		break;
						// 	default:
						// 		gameListHtml += 'guoqi1';
						// 		break;
						// }
                        //
						// gameListHtml += '.png" width="34" height="18"></em>';
						// gameListHtml += '<span>' + showName + '</span>';
						// gameListHtml += '<input type="hidden" value="' + val.shortName + '">';
						gameListHtml += '<span>' + showName + '<em>﹀</em></span>';
						gameListHtml += '<input type="hidden" value="' + val.shortName + '">';
						gameListHtml += '</p>';
					}
				});
				
				if(currentGameHtml.length < 1) {
					popTips("你不能进入游戏", "waring", "温馨提示", function() {
						gotoIndex(false, true);
					});
				}

				$('http://www.yugj881.com/resources/main/.zhuanquXz .dqxz').html(currentGameHtml);
				$('.zhuanquXz .xzxlMain').html(gameListHtml);
				init(currShortName);
			} else {
				popTips(msg.message, "error");
			}
		},
		error: function() {
			popTips("游戏加载失败", "waring", "温馨提示", function() {
				gotoIndex(false, true);
			});
		}
	});
}

/**
 * 获取彩种玩法赔率
 * @param ruleCode 玩法代码
 */
function getLotteryPlayRulesRate(ruleCode) {
	$.ajax({
		type: "post",
		url: "/ct-data/lotteryPlayRulesRate",
		data: {
			"ruleCode": ruleCode
		},
		datatype: "json",
		async: false,
		success: function(msg) {
			if (msg.sign === true) {
				var rateArr = [];
				var str = "";
				$.each(msg.rateList, function(idx, val) {
					str += val.code + ",";
					rateArr[val.code] = val.rate;
				});

				/*
				var codeRatePanels = $('.g-k-kl28-bot .guess-t li');
				for (var i = 0; i <= 27; i++) {
					var key = '' + i;
					if (i < 10) {
						key = '0' + key;
					}
					codeRatePanels.eq(i).attr("code", key);
					codeRatePanels.eq(i).find('span').eq(1).text(rateArr[key]);
				}*/
				var shangCodeRatePanels = $('#blshang li');
				for (var i = 0; i <= 9; i++) {
					var key = '' + i;
					if (i < 10) {
						key = '0' + key;
					}
					shangCodeRatePanels.eq(i).attr("code", key);
					shangCodeRatePanels.eq(i).find('span').eq(1).text("x" + rateArr[key]);
				}

				var xiaNum = 0;
				var xiaCodeRatePanels = $('#blxia li');
				for (var i = 23; i >= 14; i--) {
					var key = '' + i;
					xiaCodeRatePanels.eq(xiaNum).attr("code", key);
					xiaCodeRatePanels.eq(xiaNum).find('span').eq(1).text("x" + rateArr[key]);
					xiaNum++;
				}

				var zuoNum = 0;
				var zuoCodeRatePanels = $('#blzuo li');
				for (var i = 24; i <= 27; i++) {
					var key = '' + i;
					zuoCodeRatePanels.eq(zuoNum).attr("code", key);
					zuoCodeRatePanels.eq(zuoNum).find('span').eq(1).text("x" + rateArr[key]);
					zuoNum++;
				}

				var youNum = 0;
				var youCodeRatePanels = $('#blyou li');
				for (var i = 13; i >= 10; i--) {
					var key = '' + i;
					youCodeRatePanels.eq(youNum).attr("code", key);
					youCodeRatePanels.eq(youNum).find('span').eq(1).text("x" + rateArr[key]);
					youNum++;
				}

				$('.g-k-kl28-bot .guess-bot').empty();
				var html = '<tr>';
				html += '<td colspan="2" code="big">';
				html += '<p>BIG<span>大</span>x' + rateArr.big + '</p>';
				html += '</td>';
				html += '<td colspan="2" code="sma">';
				html += '<p>SMALL<span>小</span>x' + rateArr.sma + '</p>';
				html += '</td>';
				html += '<td code="sin"><p>ODD<span>单</span>x' + rateArr.sin + '</p></td>';
				html += '<td code="cou"><p>EVEN<span>双</span>x' + rateArr.cou + '</p></td>';
				html += '</tr>';
				html += '<tr>';
				html += '<td code="bigsin">大/单x' + rateArr.bigsin + '</td>';
				html += '<td code="bigcou">大/双x' + rateArr.bigcou + '</td>';
				html += '<td code="smasin">小/单x' + rateArr.smasin + '</td>';
				html += '<td code="smacou">小/双x' + rateArr.smacou + '</td>';
				html += '<td code="jibig"><p><span>极大</span>&nbsp;&nbsp;x' + rateArr.jibig + '</p></td>';
				html += '<td code="jisma"><p><span>极小</span>&nbsp;&nbsp;x' + rateArr.jisma + '</p></td>';
				html += '</tr>';
				$('.g-k-kl28-bot .guess-bot').html(html);
			}
		}
	});
}

/**
 * 获取最近几期的开奖号码
 * 
 * @param shortName
 *            游戏代码
 */
function getOpenCodeList(shortName) {
	$.ajax({
		url: "/ct-data/openCodeList",
		type: "post",
		dataType: "json",
		data: {
			"shortName": shortName,
			"num": 5
		},
		success: function(data) {
			$("#openCodeList").empty();
			if (data.sign === true) {
				var html = '';
				$.each(data.openCodeList, function(idx, val) {
					var sourcecode = val.sourcecode.split(",");

					html += '<tr>';
					html += '<td class="qh">' + val.expect + '</td>';
					html += '<td><ul>';

					var i = 0;
					for (i = 0; i < sourcecode.length - 1; i++) {
						html += '<li class="s"><span>' + sourcecode[i] + '</span></li>';
						html += '<li class="j">+</li>';
					}
					html += '<li class="s"><span>' + sourcecode[i] + '</span></li>';
					html += '<li class="j">=</li>';

					html += '<li class="s r"><span>' + val.openCode + '</span></li>';
					html += '</ul></td>';
					html += '</tr>';
				});
				$("#openCodeList").html(html);
			} else {
				popTips(data.message ? data.message : '获取历史开奖失败', 'error');
			}
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {}
	});
}

/**
 * 获取取开奖时间期号等信息
 * 
 * @param shortName
 *            游戏代码
 * @returns
 */
var loadOpenTimeIndex;
function loadOpenTime(shortName) {
	clearTimeout(loadOpenTimeIndex);
	var ret = null;
	var isNoRemainTime = false;
	$.ajax({
		type: "post",
		url: "/ct-data/loadOpenTime",
		data: {
			"shortName": shortName
		},
		datatype: "json",
		async: false,
		success: function(msg) {
			if (msg.sign === true) {
				if(msg.remainTime && eval(msg.remainTime) > 1) {
					way.set("showExpect.lastExpect", msg.lastFullExpect);
					way.set("showExpect.currExpect", msg.currFullExpect);
					countdownTime(msg.remainTime, loadOpenTime, shortName);
					ret = msg.lastFullExpect;
					openResult(shortName, ret);
				} else {
					isNoRemainTime = true;
				}
			} else {
				popTips(msg.message, 'waring');
			}
		}
	});
	if (ret) {
		$(".ballall").find(".ball").hide();
		$(".ballall").find(".kind").hide();
		$(".ballall").find(".ddkj").show();
		loadOpenCode(shortName, ret);
	}
	
	if(isNoRemainTime === true) {
		loadOpenTimeIndex = setTimeout(function(){
			loadOpenTime(shortName);
		}, 3000);
	}
}

/**
 * 获取开奖号码
 * 
 * @param shortName 游戏代码
 * @param expect 开奖期号
 */
var opencodeTimeOut;

function loadOpenCode(shortName, expect) {
	clearTimeout(opencodeTimeOut);
	$(".ballall").find(".ball li").hide();
	$(".ballall").find(".kind li").hide();
	$.ajax({
		url: "/ct-data/loadOpenCode",
		type: "post",
		dataType: "json",
		data: {
			"shortName": shortName,
			"expect": expect
		},
		timeout: 5000,
		success: function(data) {
			if (data.sign === true) {
				var lastExpect = eval(way.get("showExpect.lastExpect"));
				if (data.sourceCode && lastExpect == expect) {
					$(".ballall").find(".ddkj").hide();
					$(".ballall").find(".ball").show();
					$(".ballall").find(".kind").show();
					openball(expect, data.sourceCode);
				} else {
					if (lastExpect == expect) {
						opencodeTimeOut = setTimeout(function() {
							loadOpenCode(shortName, expect);
						}, 5 * 1000);
					}
				}
			} else {
				popTips(data.message, 'waring');
			}
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {}
	});
}

// 球开奖
function openball(expect, nums) {
	var arr = nums.split(",");
	var allli = $(".ballall").find(".ball li");
	var total = parseInt(arr[0]) + parseInt(arr[1]) + parseInt(arr[2]);
	var m = 0;
	var n = 0;
	for (var i = 0; i < arr.length; i++) {
		if (arr[i] % 2 === 0) {
			m++;
		} else {
			n++;
		}
	}
	if (total >= 14) {
		$(".kind li").eq(0).text("大");
	} else {
		$(".kind li").eq(0).text("小");
	}
	if (total % 2 === 0) {
		$(".kind li").eq(1).text("双");
	} else {
		$(".kind li").eq(1).text("单");
	}
	allli.eq(0).text(arr[0]).fadeIn(500, function() {
		allli.eq(1).fadeIn(500, function() {
			allli.eq(2).text(arr[1]).fadeIn(500, function() {
				allli.eq(3).fadeIn(500, function() {
					allli.eq(4).text(arr[2]).fadeIn(500, function() {
						allli.eq(5).fadeIn(500, function() {
							allli.eq(6).text(total).fadeIn(500, function() {
								$(".kind li").eq(0).fadeIn(500, function() {
									$(".kind li").eq(1).fadeIn(500, function() {

									});
								});
							});
						});
					});
				});
			});
		});
	});

	// 页面赋值
	var codePanl = $("#openCodeList");
	var html = '<tr>';
	html += '<td class="qh">' + expect + '</td>';
	html += '<td><ul>';

	var j = 0;
	for (j = 0; j < 2; j++) {
		html += '<li class="s"><span>' + arr[j] + '</span></li>';
		html += '<li class="j">+</li>';
	}
	html += '<li class="s"><span>' + arr[j] + '</span></li>';
	html += '<li class="j">=</li>';

	html += '<li class="s r"><span>' + total + '</span></li>';
	html += '</ul></td>';
	html += '</tr>';
	if (codePanl.html().indexOf(expect) == -1) {
		codePanl.prepend(html);
		// 重新加载路子
		var daxiao = '';
		var dans = '';
		if (total >= 14) {
			daxiao = "大";
		} else {
			daxiao = "小";
		}
		if (total % 2 === 0) {
			dans = "双";
		} else {
			dans = "单";
		}
		pattendaxiaonew(daxiao);
		pattendanshuangnew(dans);
	}
    if($("#openCodeList tr").length > 5){
        $("#openCodeList tr:gt(4)").remove();
    }
}

// 重新加载大小路子
function pattendaxiaonew(arr) {
	var daxiaoPanel = $("#daxiao ul");
	var cols = daxiaoPanel.eq(0).children().length;
	var text1 = daxiaoPanel.eq(0).children().eq(cols - 1).find('span').text();
	var text2 = daxiaoPanel.eq(1).children().eq(cols - 1).find('span').text();
	var text3 = daxiaoPanel.eq(2).children().eq(cols - 1).find('span').text();
	var text4 = daxiaoPanel.eq(3).children().eq(cols - 1).find('span').text();
	var text5 = daxiaoPanel.eq(4).children().eq(cols - 1).find('span').text();
	var text6 = daxiaoPanel.eq(5).children().eq(cols - 1).find('span').text();
	var rows = 0;
	var lastText = '';
	if (text6) {
		rows = 6;
		lastText = text6;
	} else if (text5) {
		rows = 5;
		lastText = text5;
	} else if (text4) {
		rows = 4;
		lastText = text4;
	} else if (text3) {
		rows = 3;
		lastText = text3;
	} else if (text2) {
		rows = 2;
		lastText = text2;
	} else if (text1) {
		rows = 1;
		lastText = text1;
	}
	var className = "";
	if (arr == '大') {
		className = "circle-da";
	} else if (arr == '小') {
		className = "circle-xiao";
	}

	var leftCss = (10 - cols) * 28;
	var width = (cols + 1) * 28;
	if (arr == lastText) {
		if (rows == 6) {
			daxiaoPanel.eq(0).append("<li><span></span></li>");
			daxiaoPanel.eq(1).append("<li><span></span></li>");
			daxiaoPanel.eq(2).append("<li><span></span></li>");
			daxiaoPanel.eq(3).append("<li><span></span></li>");
			daxiaoPanel.eq(4).append("<li><span></span></li>");
			daxiaoPanel.eq(5).append("<li class='" + className + "'><span>" + arr + "</span></li>");
			daxiaoPanel.css("left", leftCss + "px");
			daxiaoPanel.css("width", width);
		} else if (rows == 5) {
			daxiaoPanel.eq(5).children().eq(cols - 1).find('span').text(arr);
			daxiaoPanel.eq(5).children().eq(cols - 1).addClass(className);
		} else if (rows == 4) {
			daxiaoPanel.eq(4).children().eq(cols - 1).find('span').text(arr);
			daxiaoPanel.eq(4).children().eq(cols - 1).addClass(className);
		} else if (rows == 3) {
			daxiaoPanel.eq(3).children().eq(cols - 1).find('span').text(arr);
			daxiaoPanel.eq(3).children().eq(cols - 1).addClass(className);
		} else if (rows == 2) {
			daxiaoPanel.eq(2).children().eq(cols - 1).find('span').text(arr);
			daxiaoPanel.eq(2).children().eq(cols - 1).addClass(className);
		} else if (rows == 1) {
			daxiaoPanel.eq(1).children().eq(cols - 1).find('span').text(arr);
			daxiaoPanel.eq(1).children().eq(cols - 1).addClass(className);
		}
	} else {
		daxiaoPanel.eq(0).append("<li class='" + className + "'><span>" + arr + "</span></li>");
		daxiaoPanel.eq(1).append("<li><span></span></li>");
		daxiaoPanel.eq(2).append("<li><span></span></li>");
		daxiaoPanel.eq(3).append("<li><span></span></li>");
		daxiaoPanel.eq(4).append("<li><span></span></li>");
		daxiaoPanel.eq(5).append("<li><span></span></li>");
		daxiaoPanel.css("left", leftCss + "px");
		daxiaoPanel.css("width", width);
	}
}
// 重新加载路子
function pattendanshuangnew(arr) {
	var danshuangPanel = $("#danshuang ul");
	var cols = danshuangPanel.eq(0).children().length;
	var text1 = danshuangPanel.eq(0).children().eq(cols - 1).find('span').text();
	var text2 = danshuangPanel.eq(1).children().eq(cols - 1).find('span').text();
	var text3 = danshuangPanel.eq(2).children().eq(cols - 1).find('span').text();
	var text4 = danshuangPanel.eq(3).children().eq(cols - 1).find('span').text();
	var text5 = danshuangPanel.eq(4).children().eq(cols - 1).find('span').text();
	var text6 = danshuangPanel.eq(5).children().eq(cols - 1).find('span').text();
	var rows = 0;
	var lastText = '';
	if (text6) {
		rows = 6;
		lastText = text6;
	} else if (text5) {
		rows = 5;
		lastText = text5;
	} else if (text4) {
		rows = 4;
		lastText = text4;
	} else if (text3) {
		rows = 3;
		lastText = text3;
	} else if (text2) {
		rows = 2;
		lastText = text2;
	} else if (text1) {
		rows = 1;
		lastText = text1;
	}
	var className = "";
	if (arr == '单') {
		className = "circle-dan";
	} else if (arr == '双') {
		className = "circle-shuang";
	}

	var leftCss = (10 - cols) * 28;
	var width = (cols + 1) * 28;
	if (arr == lastText) {
		if (rows == 6) {
			danshuangPanel.eq(0).append("<li><span></span></li>");
			danshuangPanel.eq(1).append("<li><span></span></li>");
			danshuangPanel.eq(2).append("<li><span></span></li>");
			danshuangPanel.eq(3).append("<li><span></span></li>");
			danshuangPanel.eq(4).append("<li><span></span></li>");
			danshuangPanel.eq(5).append("<li class='" + className + "'><span>" + arr + "</span></li>");
			danshuangPanel.css("left", leftCss + "px");
			danshuangPanel.css("width", width);
		} else if (rows == 5) {
			danshuangPanel.eq(5).children().eq(cols - 1).find('span').text(arr);
			danshuangPanel.eq(5).children().eq(cols - 1).addClass(className);
		} else if (rows == 4) {
			danshuangPanel.eq(4).children().eq(cols - 1).find('span').text(arr);
			danshuangPanel.eq(4).children().eq(cols - 1).addClass(className);
		} else if (rows == 3) {
			danshuangPanel.eq(3).children().eq(cols - 1).find('span').text(arr);
			danshuangPanel.eq(3).children().eq(cols - 1).addClass(className);
		} else if (rows == 2) {
			danshuangPanel.eq(2).children().eq(cols - 1).find('span').text(arr);
			danshuangPanel.eq(2).children().eq(cols - 1).addClass(className);
		} else if (rows == 1) {
			danshuangPanel.eq(1).children().eq(cols - 1).find('span').text(arr);
			danshuangPanel.eq(1).children().eq(cols - 1).addClass(className);
		}
	} else {
		danshuangPanel.eq(0).append("<li class='" + className + "'><span>" + arr + "</span></li>");
		danshuangPanel.eq(1).append("<li><span></span></li>");
		danshuangPanel.eq(2).append("<li><span></span></li>");
		danshuangPanel.eq(3).append("<li><span></span></li>");
		danshuangPanel.eq(4).append("<li><span></span></li>");
		danshuangPanel.eq(5).append("<li><span></span></li>");
		danshuangPanel.css("left", leftCss + "px");
		danshuangPanel.css("width", width);
	}
}

/**
 * 得到当天的开奖号
 * @param shortName
 */
function getOpenCodeDayList(shortName) {
	$.ajax({
		url: "/ct-data/openCodeDayList",
		type: "post",
		dataType: "json",
		data: {
			"shortName": shortName
		},
		success: function(data) {
			if (data.sign === true) {
				var arrdaxiao = [];
				var arrdanshuang = [];
				$.each(data.openCodeList, function(idx, val) {
					if (val.openCode >= 14) {
						arrdaxiao.unshift("大");
					} else {
						arrdaxiao.unshift("小");
					}
					if (val.openCode % 2 === 0) {
						arrdanshuang.unshift("双");
					} else {
						arrdanshuang.unshift("单");
					}
				});
				pattendaxiao(arrdaxiao);
				pattendanshuang(arrdanshuang);
				tabs(".routelotHd", "cur", ".routelotBd", shortName);
			}
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {}
	});
}
//大小单双奇偶上下和值五行切换
function tabs(tabTit, on, tabCon, shortName) {
	$(tabTit).children().click(function() {
		var arr = [],
			max_len = 0,
			max_size = 0;
		$(this).addClass(on).siblings().removeClass(on);
		var index = $(tabTit).children().index(this);
		var showId = $(this).attr('data-common');
		$(tabCon).children().eq(index).show().siblings().hide();
		$("#" + showId).children().css('left', 0);

		for (var i = 0; i < 6; i++) {
			arr.push($("#" + showId).children().eq(i).children().size());
		}
		max_size = Math.max.apply(null, arr); //找出数组中的最大值
		max_len = -max_size * 28 + 308;
		var max_w = max_size * 28;
		$("#" + showId).children().animate({
			left: max_len,
			width: max_w
		}, 1500, function() {
			$(".arrow-r").addClass('hui-r').removeClass('hei-r');
			$(".arrow-l").addClass('hei-l').removeClass('hui-l');
			if (showId != 'daxiao') {
				$("#daxiao").children().css('left', 0);
			}
			if (showId != 'danshuang') {
				$("#danshuang").children().css('left', 0);
			}
		});
	});
	$('[data-common="daxiao"]').click();
}

function pattendaxiao(arr) {
	var cols = 0,
		row = 0; //cols表示列 row表示行
	var daxiaoPanel = $("#daxiao");
	daxiaoPanel.empty();
	var daxiaoHtml = [];
	daxiaoHtml[0] = '<ul class="row1">';
	daxiaoHtml[1] = '<ul class="row2">';
	daxiaoHtml[2] = '<ul class="row3">';
	daxiaoHtml[3] = '<ul class="row4">';
	daxiaoHtml[4] = '<ul class="row5">';
	daxiaoHtml[5] = '<ul class="row6">';
	for (var i = 0; i < arr.length; i++) {
		if (i == 0) {
			if (arr[i] == "大") {
				daxiaoHtml[0] += "<li class='circle-da'><span>大</span></li>";
			} else if (arr[i] == "小") {
				daxiaoHtml[0] += "<li class='circle-xiao'><span>小</span></li>";
			} else {
				daxiaoHtml[0] += "<li class='circle-he'><span>和</span></li>";
			}
		}
		if (arr[i + 1] == arr[i] || arr[i + 1] == "和" || (arr[i] == "和" && arr[i - 1] == arr[i + 1])) { //如果下一个值跟上一个值一样就排到下一行
			cols++;
			if (arr[i + 1] == "大") {
				daxiaoHtml[cols] += "<li class='circle-da'><span>大</span></li>";
			} else if (arr[i + 1] == "小") {
				daxiaoHtml[cols] += "<li class='circle-xiao'><span>小</span></li>";
			} else {
				daxiaoHtml[cols] += "<li class='circle-he'><span>和</span></li>";
			}
			//如果排到第六行，前后值还一样就继续排到第六行；
			if (cols > 5) {
				if (arr[i + 1] == "大") {
					daxiaoHtml[5] += "<li class='circle-da'><span>大</span></li>";
				} else if (arr[i + 1] == "小") {
					daxiaoHtml[5] += "<li class='circle-xiao'><span>小</span></li>";
				} else {
					daxiaoHtml[5] += "<li class='circle-he'><span>和</span></li>";
				}
				row++;
			}
		} else {
			//判断一列是否全满，如果没有全满则添加空白
			if (cols < 5) {
				for (var m = 5; m > cols; m--) {
					daxiaoHtml[m] += "<li></li>";
				}

			} else if (cols > 5) {
				for (var n = 0; n < 5; n++) {
					for (var k = 0; k < row; k++) {
						daxiaoHtml[n] += "<li></li>";
					}
				}
			}
			if (arr[i + 1] == "大") {
				daxiaoHtml[0] += "<li class='circle-da'><span>大</span></li>";
			} else if (arr[i + 1] == "小") {
				daxiaoHtml[0] += "<li class='circle-xiao'><span>小</span></li>";
			}
			cols = 0;
			row = 0;
		}
	}
	daxiaoHtml[0] += '</ul>';
	daxiaoHtml[1] += '</ul>';
	daxiaoHtml[2] += '</ul>';
	daxiaoHtml[3] += '</ul>';
	daxiaoHtml[4] += '</ul>';
	daxiaoHtml[5] += '</ul>';
	daxiaoPanel.append(daxiaoHtml[0] + daxiaoHtml[1] + daxiaoHtml[2] + daxiaoHtml[3] + daxiaoHtml[4] + daxiaoHtml[5]);
}

function pattendanshuang(arr) {
	var cols = 0,
		row = 0; //cols表示列 row表示行
	var danshuangPanel = $("#danshuang");
	danshuangPanel.empty();
	var danshuangHtml = [];
	danshuangHtml[0] = '<ul class="row1">';
	danshuangHtml[1] = '<ul class="row2">';
	danshuangHtml[2] = '<ul class="row3">';
	danshuangHtml[3] = '<ul class="row4">';
	danshuangHtml[4] = '<ul class="row5">';
	danshuangHtml[5] = '<ul class="row6">';
	for (var i = 0; i < arr.length; i++) {
		if (i == 0) {
			if (arr[i] == "单") {
				danshuangHtml[0] += "<li class='circle-dan'><span>单</span></li>";
			} else if (arr[i] == "双") {
				danshuangHtml[0] += "<li class='circle-shuang'><span>双</span></li>";
			}
		}
		if (arr[i + 1] == arr[i]) { //如果下一个值跟上一个值一样就排到下一行
			cols++;
			//console.debug(arr[i+1]);
			if (arr[i + 1] == "单") {
				danshuangHtml[cols] += "<li class='circle-dan'><span>单</span></li>";
			} else if (arr[i + 1] == "双") {
				danshuangHtml[cols] += "<li class='circle-shuang'><span>双</span></li>";
			}
			//如果排到第六行，前后值还一样就继续排到第六行；
			if (cols > 5) {
				//cols=4;
				if (arr[i + 1] == "单") {
					danshuangHtml[5] += "<li class='circle-dan'><span>单</span></li>";
				} else if (arr[i + 1] == "双") {
					danshuangHtml[5] += "<li class='circle-shuang'><span>双</span></li>";
				}
				row++;
			}
		} else {
			//判断一列是否全满，如果没有全满则添加空白
			if (cols < 5) {
				for (var m = 5; m > cols; m--) {
					danshuangHtml[m] += "<li></li>";
				}

			} else if (cols > 5) {
				for (var n = 0; n < 5; n++) {
					for (var k = 0; k < row; k++) {
						danshuangHtml[n] += "<li></li>";
					}
				}
			}
			if (arr[i + 1] == "单") {
				danshuangHtml[0] += "<li class='circle-dan'><span>单</span></li>";
			} else if (arr[i + 1] == "双") {
				danshuangHtml[0] += "<li class='circle-shuang'><span>双</span></li>";
			}
			cols = 0;
			row = 0;
		}
	}
	danshuangHtml[0] += '</ul>';
	danshuangHtml[1] += '</ul>';
	danshuangHtml[2] += '</ul>';
	danshuangHtml[3] += '</ul>';
	danshuangHtml[4] += '</ul>';
	danshuangHtml[5] += '</ul>';
	danshuangPanel.append(danshuangHtml[0] + danshuangHtml[1] + danshuangHtml[2] + danshuangHtml[3] + danshuangHtml[4] + danshuangHtml[5]);
}

/**
 * 当天投注记录
 * @param shortName
 */
function getUserBetsListToday(shortName) {
	$("#userBetsListToday").empty();
	if (!shortName) {
		shortName = currShortName;
	}
	$.ajax({
		url: "/ct-data/userBets/userBetsListToday",
		type: "post",
		dataType: "json",
		data: {
			"shortName": shortName
		},
		success: function(data) {
			if (data.sign === true) {
				var html = "";
				$.each(data.userbetList, function(idx, val) {
					html += '<tr>';
					//					html += '<td onclick="javascript:getBillInfo(\'' + val.billno + '\')">' + val.billno + '</td>';
					html += '<td><a href="javascript:getBillInfo(\'' + val.billno + '\')"><font color=grey>' + val.billno + '</font></a></td>';
					//					html += '<td>' + val.billno + '</td>';
					html += '<td>' + val.betsTimes + '</td>';
					html += '<td>' + val.ruleName + '</td>';
					html += '<td>' + val.expect + '</td>';
					html += '<td>' + val.betsMoney + '</td>';
					html += '<td>' +( val.prizeMoney? val.prizeMoney :0)+ '</td>';
					html += '<td';
					if ("未中奖" === val.state) {
						html += ' class="sty-yzj"';
					} else if ("已中奖" === val.state) {
						html += ' class="sty-ycd"';
					}
					html += '>' + val.state + '</td>';
					html += '</tr>';
				});
				$("#userBetsListToday").html(html);
			}
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {}
	});
}

/**
 * 当天投注盈亏
 * @param shortName
 */
function getUserBetsListProfitAndLossToday(shortName) {
	$("#userBetsListToday").empty();
	if (!shortName) {
		shortName = currShortName;
	}
	$.ajax({
		url: "/ct-data/userBets/userBetsListProfitAndLossToday",
		type: "post",
		dataType: "json",
		data: {
			"shortName": shortName
		},
		success: function(data) {
			if (data.sign === true) {
				var html = "";
				$.each(data.userbetList, function(idx, val) {
					html += '<tr>';
					html += '<td>' + val.billno + '</td>';
					html += '<td>' + val.betsTimes + '</td>';
					html += '<td>' + val.ruleName + '</td>';
					html += '<td>' + val.expect + '</td>';
					html += '<td>' + val.betsMoney + '</td>';
					html += '<td>' +( val.prizeMoney? val.prizeMoney :0)+ '</td>';
					html += '<td';
                    if ("未中奖" === val.state) {
                        html += ' class="sty-yzj"';
                    } else if ("已中奖" === val.state) {
                        html += ' class="sty-ycd"';
                    }
					html += '>' + val.state + '</td>';
					html += '</tr>';
				});
				$("#userBetsListToday").html(html);
			}
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {}
	});
}

/**
 * 判断是否满足切换限红条件
 * @param shortName
 */
function changeCurrlimitred(shortName, limitredid, idx) {
	if (!shortName) {
		shortName = currShortName;
	}

	$.ajax({
		url: "/ct-data/lastbet",
		type: "post",
		dataType: "json",
		data: {
			"lotteryid": shortName,
			"limitredid": limitredid
		},
		success: function(data) {
			if (!data.sign) {
				if (data.time && parseInt(data.time) > 0) {
					popTips(data.time + " 分钟后才能切换限红区", "waring");
				} else {
					//					getLimitredList(shortName);
					popTips(data.message, "error");

				}
			} else {
				way.set("http://www.yugj881.com/resources/main/currlimitred.id", limitredList[idx].id);
				way.set("http://www.yugj881.com/resources/main/currlimitred.name", limitredList[idx].name);
				way.set("currlimitred.mixmoney", limitredList[idx].mixmoney);
				way.set("currlimitred.maxmoney", limitredList[idx].maxmoney);
			}
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {}
	});
}

/**
 * 获取限红列表
 * @param shortName
 */
var limitredList = [];

function getLimitredList(shortName) {
	if (!shortName) {
		shortName = currShortName;
	}

	$.ajax({
		url: "/ct-data/limitredList",
		type: "post",
		dataType: "json",
		data: {
			"shortName": shortName
		},
		success: function(data) {
			if (data.sign === true) {
				$("#limit ul").empty();
				var html = "";
				$.each(data.list, function(idx, val) {
					limitredList[idx] = {};
					limitredList[idx].id = val.id;
					limitredList[idx].name = val.name;
					limitredList[idx].mixmoney = val.mixmoney;
					limitredList[idx].maxmoney = val.maxmoney;
					html += '<li class="cur">';
					if (val.name.indexOf('VIP')) {
						html += '<i class="vipc" >' + val.name + '</i>';
					} else if (val.name.indexOf('高级')) {
						html += '<i class="gjc" >' + val.name + '</i>';
					} else {
						html += '<i class="ylc" >' + val.name + '</i>';
					}
					html += '<span>' + val.mixmoney + '~' + val.maxmoney + '</span>';
					html += '<a class="ty" href="javascript:;"  onclick="setCurrlimitred( \'' + shortName + '\',' + idx + ');"><p>进入游戏</p></a>';
					html += '</li>';
				});
				$("#limit ul").html(html);
				pop('limit');
			}
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {}
	});
}

/**
 * 切换限红
 * @param idx
 */
function setCurrlimitred(shortName, idx) {

	changeCurrlimitred(shortName, limitredList[idx].id, idx);
	closelayer();
}

/**
 * 从cookies中获取自定义筹码
 */
function getBargainingChip() {
	var bargainingChip = [];
	bargainingChip[0] = getCookie("bargainingChip1") ? getCookie("bargainingChip1") : 50;
	bargainingChip[1] = getCookie("bargainingChip2") ? getCookie("bargainingChip2") : 100;
	bargainingChip[2] = getCookie("bargainingChip3") ? getCookie("bargainingChip3") : 500;
	bargainingChip[3] = getCookie("bargainingChip4") ? getCookie("bargainingChip4") : 1000;
	bargainingChip[4] = getCookie("bargainingChip5") ? getCookie("bargainingChip5") : 5000;

	$('.cm1').find('span').text(bargainingChip[0]);
	$('.cm2').find('span').text(bargainingChip[1]);
	$('.cm3').find('span').text(bargainingChip[2]);
	$('.cm4').find('span').text(bargainingChip[3]);
	$('.cm5').find('span').text(bargainingChip[4]);

	for (var i = 0; i < bargainingChip.length; i++) {
		$('.xiazhu-cm li').eq(i).find('input').val(bargainingChip[i]);
	}
}

/**
 * 投注
 */
function xycBetting(e) {
	var currExpect = way.get("showExpect.currExpect");
	if (!currExpect) {
		popTips("当前没有待开奖期号", "waring");
		return;
	}
	var limitredID = way.get("http://www.yugj881.com/resources/main/currlimitred.id");

	// 判断是否选中下注类型
	var isChooseGame = false;
	var gameCode = null;
	$(".g-k-kl28-bot .guess-t li").each(function(index) {
		if ($(this).hasClass("cur")) {
			gameCode = $(this).attr("code");
			isChooseGame = true;
			return false;
		}
	});
	if (!isChooseGame) {
		$(".g-k-kl28-bot .guess-bot td").each(function(index) {
			if ($(this).hasClass("cur")) {
				gameCode = $(this).attr("code");
				isChooseGame = true;
				return false;
			}
		});
	}
	if (!isChooseGame) {
		popTips("请选择游戏类型", "waring");
		return;
	}

	var orderTotal = $('#sumBetAmount').val();
	var mixmoney = way.get("currlimitred.mixmoney");
	var maxmoney = way.get("currlimitred.maxmoney");
	if (!orderTotal) {
		popTips("请输入投注金额", "waring");
		return;
	}

	if (!mixmoney || !maxmoney) {
		popTips("请刷新后重试", "waring");
		return;
	}

	orderTotal = parseFloat(orderTotal);
	mixmoney = parseInt(mixmoney);
	maxmoney = parseInt(maxmoney);
	if (orderTotal < mixmoney || orderTotal > maxmoney) {
		popTips("当前投注限额为" + mixmoney + " ~ " + maxmoney, "waring");
		return;
	}
	$(e.target).attr("onclick", "");
	$.ajax({
		url: "/ct-data/userBets/xycbuy",
		type: "post",
		dataType: "json",
		data: {
			"shortName": currShortName,
			"currExpect": currExpect,
			"codes": gameCode,
			"total": orderTotal,
			"limitredID": limitredID
		},
		success: function(data) {
			if (data.sign === true) {
				$('#sumBetAmount').val("0");
				$(".g-k-kl28-bot .guess-t li").removeClass("cur");
				$(".g-k-kl28-bot .guess-bot td").removeClass("cur");

				popTips(data.message, "succeed");
				dsFlushBalance();
				getUserBetsListToday();
			} else {
				popTips(data.message, "error");
			}
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {},
		complete : function() {
			$(e.target).attr("onclick", "xycBetting(event);");
		}
	});
	$(".g-k-kl28-bot .guess-t li").removeClass("cur");
	$("table.guess-bot td").removeClass("cur");
}

$(function() {
	var searchStr = window.location.search;
	var xycCode = getQueryString(searchStr.substr(1), "code");
	if (!xycCode) {
		xycCode = 'xy28';
	}
	getGameList("xingyuncai", xycCode);
	getLotteryPlayRulesRate("xy28qw");
	getBargainingChip();

	// ===========================彩票路单轮播==========================================================//
	$(".arrow-r").on("click", function() {
		var temp_index, max_len, diffvalue, max_size, arr = [],
			left_num;
		temp_index = $("http://www.yugj881.com/resources/main/.keno-path-teb li.cur").index();
		var lotteryRouteChildren = $("#lotteryRoute div").eq(temp_index).children();
		left_num = lotteryRouteChildren.eq(0).css("left");
		for (var i = 0; i < 6; i++) {
			arr.push(lotteryRouteChildren.eq(i).children().size());
		}
		max_size = 0;
		for (i = 0; i < arr.length; i++) {
			if (max_size <= arr[i]) {
				max_size = arr[i];
			}
		}
		max_len = -max_size * 28 + 308;
		left_num = parseInt(left_num.split("px")[0]);
		diffvalue = max_len - left_num; // 移动的差值
		if ($(".arrow-r").hasClass("hei-r")) {
			if (diffvalue > - 308) {
				lotteryRouteChildren.animate({
					left: max_len
				}, 500);
				$(".arrow-r").addClass('hui-r').removeClass('hei-r');
				$(".arrow-l").addClass('hei-l').removeClass('hui-l');
			} else {
				lotteryRouteChildren.animate({
					left: left_num - 308
				}, 500);
				$(".arrow-r").addClass('hei-r').removeClass('hui-r');
				$(".arrow-l").addClass('hei-l').removeClass('hui-l');
			}
		}

	});
	$(".arrow-l").on("click", function() {
		var temp_index, temp_left, left_num;
		temp_index = $("http://www.yugj881.com/resources/main/.keno-path-teb li.cur").index();
		var lotteryRouteChildren = $("#lotteryRoute div").eq(temp_index).children();
		left_num = lotteryRouteChildren.eq(0).css("left");
		left_num = parseInt(left_num.split("px")[0]);
		if ($(".arrow-l").hasClass("hei-l")) {
			if (left_num >= -308) {
				lotteryRouteChildren.animate({
					left: 0
				}, 500);
				$(".arrow-l").addClass('hui-l').removeClass('hei-l');
				$(".arrow-r").addClass('hei-r').removeClass('hui-r');
			} else {
				lotteryRouteChildren.animate({
					left: left_num + 308
				}, 500);
				$(".arrow-l").addClass('hei-l').removeClass('hui-l');
				$(".arrow-r").addClass('hei-r').removeClass('hui-r');
			}
		}
	});

	// 选号
	$('.g-k-kl28-bot .guess-t li').on("click", function() {
		$('.g-k-kl28-bot .guess-t li').removeClass();
		$('.g-k-kl28-bot .guess-bot td').removeClass();
		$(this).addClass('cur');
	});
	$('.g-k-kl28-bot .guess-bot td').on("click", function() {
		$('.g-k-kl28-bot .guess-t li').removeClass();
		$('.g-k-kl28-bot .guess-bot td').removeClass();
		$(this).addClass('cur');
	});

	// 筹码点击事件
	$('.xiazhu-cm em li').on("click", function() {
		if ($(this).parent().find('input').attr("disabled") != "disabled") {
			return;
		}
		var total = $('#sumBetAmount').val();
		if (!total) {
			total = 0;
		}
		var addMoney = $(this).parent().find('input').val();
		if (!addMoney) {
			addMoney = 0;
		}
		total = parseFloat(total) + parseInt(addMoney);
		$('#sumBetAmount').val(total);
	});
});


var flag = true;

function userCustom() {
	if (flag) {
		$(".xiazhu-cm button").html("自定义");
		$('.cm1').find('input').attr("disabled", true);
		$('.cm2').find('input').attr("disabled", true);
		$('.cm3').find('input').attr("disabled", true);
		$('.cm4').find('input').attr("disabled", true);
		$('.cm5').find('input').attr("disabled", true);

		$('.cm1').find('input').attr("hidden", true);
		$('.cm2').find('input').attr("hidden", true);
		$('.cm3').find('input').attr("hidden", true);
		$('.cm4').find('input').attr("hidden", true);
		$('.cm5').find('input').attr("hidden", true);
		$('.cm1').find('span').attr("hidden", false);
		$('.cm2').find('span').attr("hidden", false);
		$('.cm3').find('span').attr("hidden", false);
		$('.cm4').find('span').attr("hidden", false);
		$('.cm5').find('span').attr("hidden", false);

		getBargainingChip();

		$('#userBetDiv').show();
		$('#userCustomDiv').hide();

		flag = false;
	} else {
		$(".xiazhu-cm button").html("取消");
		$('.cm1').find('input').attr("disabled", false);
		$('.cm2').find('input').attr("disabled", false);
		$('.cm3').find('input').attr("disabled", false);
		$('.cm4').find('input').attr("disabled", false);
		$('.cm5').find('input').attr("disabled", false);

		$('.cm1').find('input').attr("hidden", false);
		$('.cm2').find('input').attr("hidden", false);
		$('.cm3').find('input').attr("hidden", false);
		$('.cm4').find('input').attr("hidden", false);
		$('.cm5').find('input').attr("hidden", false);
		$('.cm1').find('span').attr("hidden", true);
		$('.cm2').find('span').attr("hidden", true);
		$('.cm3').find('span').attr("hidden", true);
		$('.cm4').find('span').attr("hidden", true);
		$('.cm5').find('span').attr("hidden", true);

		getBargainingChip();

		$('#userBetDiv').hide();
		$('#userCustomDiv').show();
		flag = true;
	}
}

/**
 * 保存自定义筹码
 */
function saveUserCustomChips() {
	// 自定义筹码事件
	setCookie("bargainingChip1", $('.cm1').find('input').val(), 365);
	setCookie("bargainingChip2", $('.cm2').find('input').val(), 365);
	setCookie("bargainingChip3", $('.cm3').find('input').val(), 365);
	setCookie("bargainingChip4", $('.cm4').find('input').val(), 365);
	setCookie("bargainingChip5", $('.cm5').find('input').val(), 365);

	$('.cm1').find('span').text($('.cm1').find('input').val());
	$('.cm2').find('span').text($('.cm2').find('input').val());
	$('.cm3').find('span').text($('.cm3').find('input').val());
	$('.cm4').find('span').text($('.cm4').find('input').val());
	$('.cm5').find('span').text($('.cm5').find('input').val());

	userCustom();
}

//异步去取上一次的开奖结果和中奖情况
function openResult(shortName, expect) {
	$.ajax({
		type: "post",
		url: "/ct-data/userBets/openResult",
		data: {
			"shortName": shortName,
			"expect": expect
		},
		datatype: "json",
		success: function(msg) {
			if (msg.sign) {
				if (msg.isOpen) {
					if (msg.money[0].prizeMoney > 0) {
						$(".touzhuzj ul").empty();
						var showName = msg.showName.trim();
						if (showName == "幸运28") {
							showName = "北京幸运28";
						}
						var insertHtml = "<li>投注彩种：<span>" + showName + "</span></li>";
						insertHtml += "<li>投注期号：<span>" + msg.expect + "</span></li>";
                        insertHtml += "<li>投注金额：<span>" + msg.money[0].totalMoney + "元</span></li>";
                        insertHtml += "<li>中奖金额：<span>" + msg.money[0].prizeMoney + "元</span></li>";
                        insertHtml += "<li>本次盈亏：<span>" + (eval(msg.money[0].prizeMoney) - eval(msg.money[0].totalMoney)).toFixed(4) + "元</span></li>";
						$(".touzhuzj ul").html(insertHtml);
						// pop('kjts','320px','250px');
						$(".touzhuzj").html($(".touzhuzj").html()).show(300).delay(30000).hide(300);
						audioPlay(1);
						// $("#kjts").html().show(300).delay(3000).hide(300);
					}
					getUserBetsListToday();
				} else {
					setTimeout(function() {
						openResult(shortName, expect);
					}, 5 * 1000);
				}
			} else {
				popTips(msg.message, "error");
			}
		}
	});
}